<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>轮播图</title>
  <style>
    * {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
    }

    .slider {
      width: 560px;
      height: 400px;
      margin: 0 auto;
      overflow: hidden;
      position: relative;
    }

    .slider-wrapper {
      width: 100%;
      height: 320px;
    }

    .slider-wrapper img {
      width: 100%;
      height: 100%;
      display: block;
      object-fit: cover;
    }

    .slider-footer {
      height: 80px;
      background-color: rgb(100, 67, 68);
      padding: 12px 12px 0 12px;
      position: relative;
    }

    .slider-footer p {
      color: #fff;
      font-size: 18px;
      margin-bottom: 10px;
    }

    .slider-indicator {
      display: flex;
      list-style: none;
    }

    .slider-indicator li {
      width: 8px;
      height: 8px;
      margin: 0 4px;
      border-radius: 50%;
      background: #fff;
      opacity: 0.4;
      cursor: pointer;
      transition: all 0.3s;
    }

    .slider-indicator li.active {
      width: 12px;
      height: 12px;
      opacity: 1;
    }

    .slider-control {
      position: absolute;
      right: 12px;
      top: 12px;
      display: flex;
    }

    .slider-control button {
      width: 28px;
      height: 28px;
      margin-left: 12px;
      background: rgba(255, 255, 255, 0.1);
      color: #fff;
      border: none;
      border-radius: 4px;
      cursor: pointer;
      font-size: 16px;
      transition: background 0.3s;
    }

    .slider-control button:hover {
      background: rgba(255, 255, 255, 0.2);
    }
  </style>
</head>
<body>
  <div class="slider">
    <div class="slider-wrapper">
      <img src="/study-js/作业/webAPI/Snipaste_2025-10-17_14-19-44.png" alt="轮播图">
    </div>
    <div class="slider-footer">
      <p>对人类来说会不会太超前了？</p>
      <ul class="slider-indicator">
        <li class="active"></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
      </ul>
      <div class="slider-control">
        <button class="prev">&lt;</button>
        <button class="next">&gt;</button>
      </div>
    </div>
  </div>

  <script>
    // 轮播图数据
    const sliderData = [
      { url: '/study-js/作业/webAPI/Snipaste_2025-10-17_14-19-44.png', title: '对人类来说会不会太超前了？', color: 'rgb(100, 67, 68)' },
      { url: '/study-js/作业/webAPI/Snipaste_2025-10-17_14-19-44.png', title: '开启剑与雪的黑暗传说！', color: 'rgb(43, 35, 26)' },
      { url: '/study-js/作业/webAPI/Snipaste_2025-10-17_14-19-44.png', title: '真正的jo厨出现了！', color: 'rgb(36, 31, 33)' },
      { url: '/study-js/作业/webAPI/Snipaste_2025-10-17_14-19-44.png', title: '快来分享你的寒假日常吧~', color: 'rgb(139, 98, 66)' },
      { url: '/study-js/作业/webAPI/Snipaste_2025-10-17_14-19-44.png', title: '李玉刚：让世界通过B站看到东方大国文化', color: 'rgb(67, 90, 92)' },
      { url: '/study-js/作业/webAPI/Snipaste_2025-10-17_14-19-44.png', title: '哔哩哔哩小年YEAH', color: 'rgb(166, 131, 143)' },
      { url: '/study-js/作业/webAPI/Snipaste_2025-10-17_14-19-44.png', title: '一站式解决你的电脑配置问题！！！', color: 'rgb(53, 29, 25)' },
      { url: '/study-js/作业/webAPI/Snipaste_2025-10-17_14-19-44.png', title: '谁不想和小猫咪贴贴呢！', color: 'rgb(99, 72, 114)' },
    ]

    // 获取DOM元素
    const slider = document.querySelector('.slider');
    const img = document.querySelector('.slider-wrapper img');
    const title = document.querySelector('.slider-footer p');
    const footer = document.querySelector('.slider-footer');
    const indicators = document.querySelectorAll('.slider-indicator li');
    const prevBtn = document.querySelector('.prev');
    const nextBtn = document.querySelector('.next');

    let currentIndex = 0;
    let timer = null;

    // 更新轮播图
    function updateSlider(index) {
      // 边界检查
      if (index < 0) index = sliderData.length - 1;
      if (index >= sliderData.length) index = 0;
      
      currentIndex = index;
      
      // 更新图片和文字
      img.src = sliderData[currentIndex].url;
      img.alt = sliderData[currentIndex].title;
      title.textContent = sliderData[currentIndex].title;
      footer.style.backgroundColor = sliderData[currentIndex].color;
      
      // 更新指示器
      indicators.forEach((indicator, i) => {
        indicator.classList.toggle('active', i === currentIndex);
      });
    }

    // 下一张
    function nextSlide() {
      updateSlider(currentIndex + 1);
    }

    // 上一张
    function prevSlide() {
      updateSlider(currentIndex - 1);
    }

    // 自动播放
    function startAutoPlay() {
      timer = setInterval(nextSlide, 3000);
    }

    // 停止自动播放
    function stopAutoPlay() {
      clearInterval(timer);
    }

    // 事件监听
    nextBtn.addEventListener('click', nextSlide);
    prevBtn.addEventListener('click', prevSlide);

    // 指示器点击
    indicators.forEach((indicator, index) => {
      indicator.addEventListener('click', () => {
        updateSlider(index);
      });
    });

    // 鼠标悬停暂停
    slider.addEventListener('mouseenter', stopAutoPlay);
    slider.addEventListener('mouseleave', startAutoPlay);

    // 初始化
    updateSlider(0);
    startAutoPlay();
  </script>
</body>
</html>